<?php #//AJAX PHP PENNY AUCTION v.1.1

#///////////////////////////////////////////////////////////
#//  COPYRIGHT 2009 Aaron Helmlinger ALL RIGHTS RESERVED  //
#///////////////////////////////////////////////////////////<?php


  
include "./includes/config.inc.php";
//echo "<meta http-equiv='refresh' content='1;URL=www.php-mysql-video.ru'>";

  $query = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_version_1_3 WHERE id='1'"));
  
   $admin_daily_win_limits = $query['daily_win_limits'];
 $admin_weekly_win_limits = $query['weekly_win_limits'];
   $admin_monthly_win_limits = $query['monthly_win_limits'];
  
  
      $query = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_version_1_4 WHERE id='1'"));
  
   $admin_beginner_auction_limit = $query['beginner_auction_limit'];
 
           $query = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_version_2_1 WHERE id='1'"));
  
   $admin_elite_auction_limit = $query['elite_auction_limit'];
   $admin_force_paid_limit = $query['force_payment_limit'];


$TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));
                        
$NOW = date("YmdHis",$TIME);


   $jsenddate = "";

$jsenddate .= substr ($NOW, 4, 2);
$jsenddate .= "/";
$jsenddate .= substr ($NOW, 6, 2);
$jsenddate .= "/";
$jsenddate .= substr ($NOW, 0, 4);
$jsenddate .= " ";


     
if (substr ($NOW, 8, 2) > 12) {
$jsenddate .= substr ($NOW, 8, 2)-12;
$jsampm = "PM";
}
if (substr ($NOW, 8, 2) != 00){
if (substr ($NOW, 8, 2) < 12) {
$jsenddate .= substr ($NOW, 8, 2);
$jsampm = "AM";
}}
if (substr ($NOW, 8, 2) == 12) {
$jsenddate .= substr ($NOW, 8, 2);
$jsampm = "PM";
}
if (substr ($NOW, 8, 2) == 00) {
$jsenddate .= 12;
$jsampm = "AM";
}

$jsenddate .= ":";
$jsenddate .= substr ($NOW, 10, 2);
$jsenddate .= ":";
$jsenddate .= substr ($NOW, 12, 2);
$jsenddate .= " ";
$jsenddate .= $jsampm;

$NOW2 = $jsenddate;


$auction_id = intval($_GET['id']);      
$id2 = $_SESSION["PHPAUCTION_LOGGED_IN"];

       $query435 = mysql_fetch_array(mysql_query("SELECT bid_credits_reqd,ends,ae_activation,ae_increment,time_increment,auction_type2,dbl_bidding,hard_reset,notimer,current_bid,reserve_price,increment,lockout,seat_qty FROM PHPAUCTIONXL_auctions WHERE id='$auction_id' "));
            $dbl_bidding_check = $query435['dbl_bidding'];
              $hard_reset_check = $query435['hard_reset'];
             $notimer = $query435['notimer'];
             $notimer_reserve_price = $query435['reserve_price'];
              $notimer_current_bid = $query435['current_bid'];
               $notimer_bid_increment = $query435['increment'];
                   $lockout = $query435['lockout'];
                   $seat_qty = $query435['seat_qty']; 
                   
                   
                   
                   
                                  
             if ( $notimer == 1 ) {
              
             $notimer_reserve_price = $notimer_reserve_price + .01;
             
             if ( $notimer_current_bid >= $notimer_reserve_price ) {
                  //echo $notimer_current_bid;
                  //echo "<BR>";
                  //echo $notimer_reserve_price;
             exit;             
             
             }
             
              }
              
              
             $queryunpaid = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND closed=1 AND paid=0";
$resultunpaid = mysql_query($queryunpaid);
$user_unpaid = mysql_num_rows($resultunpaid);


if ( $user_unpaid > $admin_force_paid_limit ) {

echo "unpaid";

    exit;
} 
              
              
              
$query_check_for_previous_bid = mysql_fetch_array(mysql_query("SELECT current_high_bidder,bidder FROM PHPAUCTIONXL_bids WHERE auction='$auction_id' ORDER BY id DESC LIMIT 1"));
     $current_high_bidder_check = $query_check_for_previous_bid['current_high_bidder'];
     $current_high_bidder_check2 = $query_check_for_previous_bid['bidder'];
    
    if ( $dbl_bidding_check == 0 ) {
     
     if ( $current_high_bidder_check != $_SESSION['PHPAUCTION_LOGGED_IN_USERNAME'] && $current_high_bidder_check2 != $_SESSION["PHPAUCTION_LOGGED_IN"] ) {
     
   
           if( $id2 != "" ) {
           
      
      
      $query = "select nick,bids_remaining,daily_wins from PHPAUCTIONXL_users
         WHERE id=$id2";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);

 $i = 0;
while($i < $num_auction) {

  $username 	= mysql_result($result,$i,"nick");
  //     $user_daily_win_limits =mysql_result($result,$i,"daily_win_limits");
 //$user_weekly_win_limits = mysql_result($result,$i,"weekly_win_limits");
  // $user_monthly_win_limits = mysql_result($result,$i,"monthly_win_limits");
  $bids_remaining 	= mysql_result($result,$i,"bids_remaining");
  $beginner_wins 	= mysql_result($result,$i,"daily_wins");
$i++;
}

// CREATE WIN LIMIT DATES

    $daylimitdatestart = substr ($NOW, 0, 8);
    $daylimitdatestart .= "000000";
         // echo $daylimitdatestart."<BR>";

    $TIMEdaylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+1,date("Y"));

$NOWdaylimitdateend = date("YmdHis",$TIMEdaylimitdateend);

     $daylimitdateend = substr ($NOWdaylimitdateend, 0, 8);
    $daylimitdateend .= "000000";
          // echo $daylimitdateend."<BR>";
         $monthlylimitdatestart = substr ($NOW, 0, 6);
    $monthlylimitdatestart .= "01000000"; 
           // echo $monthlylimitdatestart."<BR>";
    
    $TIMEmonthlylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m")+1, date("d"),date("Y"));

$NOWmonthlylimitdateend = date("YmdHis",$TIMEmonthlylimitdateend);

     $monthlylimitdateend = substr ($NOWmonthlylimitdateend, 0, 6);
    $monthlylimitdateend .= "01000000";
                    // echo $monthlylimitdateend."<BR>";
    $jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$text_day = (jddayofweek($jd,1));

          //   echo $text_day;
    if ( $text_day == "Monday" ) {
        $day_correct_backwards = -1;
        $day_correct_forwards = 6;
    }  
    if ( $text_day == "Tuesday" ) {
        $day_correct_backwards = -2;
        $day_correct_forwards =5;
    }
    if ( $text_day == "Wednesday" ) {
        $day_correct_backwards = -3;
        $day_correct_forwards = 4;
    }
        if ( $text_day == "Thursday" ) {
        $day_correct_backwards = -4;
        $day_correct_forwards = 3;
    }
    if ( $text_day == "Friday" ) {
        $day_correct_backwards = -5;
        $day_correct_forwards =2;
    }
    if ( $text_day == "Saturday" ) {
        $day_correct_backwards = -6;
        $day_correct_forwards =1;
    }
    if ( $text_day == "Sunday" ) {
        $day_correct_backwards = 0;
        $day_correct_forwards = 7;
    }
    
        //  echo $day_correct_backwards;
      //  echo $day_correct_forwards;
$TIMEweeklylimitdatestart = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+$day_correct_backwards,date("Y"));

$NOWweeklylimitdatestart = date("YmdHis",$TIMEweeklylimitdatestart);
    
        $weeklylimitdatestart = substr ($NOWweeklylimitdatestart, 0, 8);
    $weeklylimitdatestart .= "000000";

        // echo $weeklylimitdatestart."<BR>";
  
  $TIMEweeklylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+$day_correct_forwards,date("Y"));

$NOWweeklylimitdateend = date("YmdHis",$TIMEweeklylimitdateend);
    
        $weeklylimitdateend = substr ($NOWweeklylimitdateend, 0, 8);
    $weeklylimitdateend .= "000000";
    //echo $weeklylimitdateend."<BR>";

// Query Auctions For Limits  
  
  
    $querydaily = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND closed=1 AND
         ends > $daylimitdatestart AND
         ends < $daylimitdateend";
$resultdaily = mysql_query($querydaily);
$user_daily_wins = mysql_num_rows($resultdaily);

if ( $user_daily_wins >= $admin_daily_win_limits ) {

echo "daily";

    exit;
}

       
          $queryweekly = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND 
         closed=1 AND
         ends > $weeklylimitdatestart AND
         ends < $weeklylimitdateend";
$resultweekly = mysql_query($queryweekly);
$user_weekly_wins = mysql_num_rows($resultweekly);


if ( $user_weekly_wins >= $admin_weekly_win_limits ) {

echo "weekly";

    exit;
}



     $querymonthly = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND 
         closed=1 AND
         ends > $monthlylimitdatestart AND
         ends < $monthlylimitdateend";
$resultmonthly= mysql_query($querymonthly);
$user_monthly_wins = mysql_num_rows($resultmonthly);


    if ( $user_monthly_wins >= $admin_monthly_win_limits ) {

echo "monthly";

    exit;
}

            





  

 $auctionends = $query435['ends'];
  $item_extend_activated = $query435['ae_activation'];
  $item_extend_increment = $query435['ae_increment'];
  $bid_credits_reqd1 = $query435['bid_credits_reqd'];
  $auction_type2 = $query435['auction_type2'];
  
     
     
      if ( $bids_remaining <= 0 ) {
       if ( $bid_credits_reqd1  > 0 ) {
    
echo "nobids";

    exit;
}
 } 
  
  
       if ( $lockout == 1 ) {
       
    $___END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) - 6, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
       
       if (($___END - $TIME) <= 180) {     
       
       
          $query = "select * from PHPAUCTIONXL_bids2
         WHERE bidder=$id2 AND auction=$auction_id";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);

if ( $num_auction == 0 ) {
       
           
echo "lockout";

    exit;
    
    }
    
    }
} 
  
 
            
      if ( $auction_type2 == "beginner" ) {
           if ( $beginner_wins >= $admin_beginner_auction_limit ){
echo "beginner";
    exit;
    }
}
  
           if ( $auction_type2 == "elite" ) {
           if ( $beginner_wins <= $admin_elite_auction_limit ){
echo "elite";
    exit;
    }
}

           if ( $seat_qty > 0 ) {
  
$queryseats = "select * from PHPAUCTIONXL_auction_seats
         WHERE auctionid=$auction_id AND userid=$id2";
$resultseats = mysql_query($queryseats);
$num_auctionseats = mysql_num_rows($resultseats);   

if ( $num_auctionseats == 0 ) {

     $queryseats2 = "select * from PHPAUCTIONXL_auction_seats
         WHERE auctionid=$auction_id";
$resultseats2 = mysql_query($queryseats2);
$num_auctionseats2 = mysql_num_rows($resultseats2); 
           
           if ( $num_auctionseats2 >= $seat_qty ){
echo "seatsfull";
    exit;
    }

      if ( $num_auctionseats2 < ($seat_qty + 1) ){

$query12 = "INSERT INTO PHPAUCTIONXL_auction_seats VALUES";

$query12 .= "(NULL";
$query12 .= ",";
$query12 .= $id2;
$query12 .= ",";
$query12 .= $auction_id;
$query12 .= ",";
$query12 .= 1;
$query12 .= ",";
$query12 .= 0;
$query12 .= ")";

mysql_query($query12);

     $seatsupdate = $num_auctionseats2 +1;

$query34="UPDATE PHPAUCTIONXL_auctions2 SET seats_taken='$seatsupdate' WHERE id='$auction_id'";

mysql_query($query34);


}

}
}



  
     if ( $hard_reset_check == 0) {
  
  
  if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) - 6, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            
            if (($__END - $TIME) <= $EXTSETTINGS['timebefore']) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + $EXTSETTINGS['extend'] , substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }


            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) - 6, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            
            if (($__END - $TIME) <= $item_extend_activated ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + $item_extend_increment , substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

 
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

              }
              
              
              
              if ( $hard_reset_check == 1) {
              
              
                        if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            $TIME_EXTEND = $EXTSETTINGS['timebefore'];
                     
                         $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $EXTSETTINGS['extend'] - $timeremaining22;
              
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

   
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
                $TIME_EXTEND = $item_extend_activated;
                          $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $item_extend_increment - $timeremaining22;
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

   
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

}



$query99 = "select current_high_bidder,current_bid,increment,closed from PHPAUCTIONXL_auctions
         WHERE id=$auction_id";
$result = mysql_query($query99);
$num_auction = mysql_num_rows($result);

 $i = 0;
while($i < $num_auction) {

  $high_bidder 	= mysql_result($result,$i,"current_high_bidder");
$high_bid 	= mysql_result($result,$i,"current_bid");
   $increment 	= mysql_result($result,$i,"increment");
//   $closed = mysql_result($result,$i,"closed"); 
   
   
$i++;
}

          if ( $high_bidder != $_SESSION['PHPAUCTION_LOGGED_IN_USERNAME'] ) {

                              
      if ( $increment > 0 ) {          
$high_bid = $high_bid + $increment;
                             }
                             
       if ( $increment < 0 ) {
       if( $high_bid > .01 ) {          
$high_bid = $high_bid + $increment;
                             } }                           

if ( $increment < 0 ) {
       if( $high_bid <= .01 ) {          
$high_bid = .01;
                             } }                            
           

if ($closed == 0 ) {              
        if ( $bids_remaining >= $bid_credits_reqd1 ) {

    $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id";
                mysql_query($query69);
                      
                  $query692 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id";
                mysql_query($query692);


$query1 = "INSERT INTO PHPAUCTIONXL_bids VALUES";

$query1 .= "(NULL";
$query1 .= ",";
$query1 .= $auction_id;
$query1 .= ",";
$query1 .= $id2;
$query1 .= ",";
$query1 .= $high_bid;
$query1 .= ",";
$query1 .= $NOW;
$query1 .= ",";
$query1 .= "1";
$query1 .= ",";
$query1 .= "'";
$query1 .= $username;
$query1 .= "'";
$query1 .= ",";
$query1 .= "'unique'";
$query1 .= ")";
            
            
            
mysql_query($query1);

$query12 = "INSERT INTO PHPAUCTIONXL_bids2 VALUES";

$query12 .= "(NULL";
$query12 .= ",";
$query12 .= $auction_id;
$query12 .= ",";
$query12 .= $id2;
$query12 .= ",";
$query12 .= $high_bid;
$query12 .= ",";
$query12 .= $NOW;
$query12 .= ",";
$query12 .= "1";
$query12 .= ",";
$query12 .= "'";
$query12 .= $username;
$query12 .= "'";
$query12 .= ",";
$query12 .= "'unique'";
$query12 .= ")";
            
            
            
mysql_query($query12);


            
              

$query33="UPDATE PHPAUCTIONXL_auctions SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$auction_id'";

mysql_query($query33);


$query33a="UPDATE PHPAUCTIONXL_auctions2 SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$auction_id'";

mysql_query($query33a);



$bids_remaining2 = $bids_remaining - $bid_credits_reqd1;
 
 $query34="UPDATE PHPAUCTIONXL_users SET bids_remaining='$bids_remaining2' WHERE id='$id2'";

mysql_query($query34);



    $query99a = "select * from PHPAUCTIONXL_bids WHERE auction='$auction_id' ORDER BY id";
$result = mysql_query($query99a);
$num_auction = mysql_num_rows($result);

if ( $num_auction > 15 ) {

   $bidwhen1 	= mysql_result($result,2,"id");

     $removeold="DELETE from PHPAUCTIONXL_bids where id<'$bidwhen1' AND auction='$auction_id'";
mysql_query($removeold);

}









$echo22 = "yes|";










$echo22 .= $bid_credits_reqd1;

echo $echo22;

   }
}

}

}  
   
   }   
   
   }
   
   
   
 if ( $dbl_bidding_check == 1 ) {
     
     if ( 1 != 2 && 1 != 2 ) {
     
   
           if( $id2 != "" ) {
           
      
      
      $query = "select nick,bids_remaining,daily_wins from PHPAUCTIONXL_users
         WHERE id=$id2";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);

 $i = 0;
while($i < $num_auction) {

  $username 	= mysql_result($result,$i,"nick");
  //     $user_daily_win_limits =mysql_result($result,$i,"daily_win_limits");
 //$user_weekly_win_limits = mysql_result($result,$i,"weekly_win_limits");
  // $user_monthly_win_limits = mysql_result($result,$i,"monthly_win_limits");
  $bids_remaining 	= mysql_result($result,$i,"bids_remaining");
  $beginner_wins 	= mysql_result($result,$i,"daily_wins");
$i++;
}

// CREATE WIN LIMIT DATES

    $daylimitdatestart = substr ($NOW, 0, 8);
    $daylimitdatestart .= "000000";
         // echo $daylimitdatestart."<BR>";

    $TIMEdaylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+1,date("Y"));

$NOWdaylimitdateend = date("YmdHis",$TIMEdaylimitdateend);

     $daylimitdateend = substr ($NOWdaylimitdateend, 0, 8);
    $daylimitdateend .= "000000";
          // echo $daylimitdateend."<BR>";
         $monthlylimitdatestart = substr ($NOW, 0, 6);
    $monthlylimitdatestart .= "01000000"; 
           // echo $monthlylimitdatestart."<BR>";
    
    $TIMEmonthlylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m")+1, date("d"),date("Y"));

$NOWmonthlylimitdateend = date("YmdHis",$TIMEmonthlylimitdateend);

     $monthlylimitdateend = substr ($NOWmonthlylimitdateend, 0, 6);
    $monthlylimitdateend .= "01000000";
                    // echo $monthlylimitdateend."<BR>";
    $jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$text_day = (jddayofweek($jd,1));

          //   echo $text_day;
    if ( $text_day == "Monday" ) {
        $day_correct_backwards = -1;
        $day_correct_forwards = 6;
    }  
    if ( $text_day == "Tuesday" ) {
        $day_correct_backwards = -2;
        $day_correct_forwards =5;
    }
    if ( $text_day == "Wednesday" ) {
        $day_correct_backwards = -3;
        $day_correct_forwards = 4;
    }
        if ( $text_day == "Thursday" ) {
        $day_correct_backwards = -4;
        $day_correct_forwards = 3;
    }
    if ( $text_day == "Friday" ) {
        $day_correct_backwards = -5;
        $day_correct_forwards =2;
    }
    if ( $text_day == "Saturday" ) {
        $day_correct_backwards = -6;
        $day_correct_forwards =1;
    }
    if ( $text_day == "Sunday" ) {
        $day_correct_backwards = 0;
        $day_correct_forwards = 7;
    }
    
        //  echo $day_correct_backwards;
      //  echo $day_correct_forwards;
$TIMEweeklylimitdatestart = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+$day_correct_backwards,date("Y"));

$NOWweeklylimitdatestart = date("YmdHis",$TIMEweeklylimitdatestart);
    
        $weeklylimitdatestart = substr ($NOWweeklylimitdatestart, 0, 8);
    $weeklylimitdatestart .= "000000";

        // echo $weeklylimitdatestart."<BR>";
  
  $TIMEweeklylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+$day_correct_forwards,date("Y"));

$NOWweeklylimitdateend = date("YmdHis",$TIMEweeklylimitdateend);
    
        $weeklylimitdateend = substr ($NOWweeklylimitdateend, 0, 8);
    $weeklylimitdateend .= "000000";
    //echo $weeklylimitdateend."<BR>";

// Query Auctions For Limits  
  
  
    $querydaily = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND closed=1 AND
         ends > $daylimitdatestart AND
         ends < $daylimitdateend";
$resultdaily = mysql_query($querydaily);
$user_daily_wins = mysql_num_rows($resultdaily);

if ( $user_daily_wins >= $admin_daily_win_limits ) {

echo "daily";

    exit;
}

       
          $queryweekly = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND 
         closed=1 AND
         ends > $weeklylimitdatestart AND
         ends < $weeklylimitdateend";
$resultweekly = mysql_query($queryweekly);
$user_weekly_wins = mysql_num_rows($resultweekly);


if ( $user_weekly_wins >= $admin_weekly_win_limits ) {

echo "weekly";

    exit;
}



     $querymonthly = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$_SESSION[PHPAUCTION_LOGGED_IN_USERNAME]' AND 
         closed=1 AND
         ends > $monthlylimitdatestart AND
         ends < $monthlylimitdateend";
$resultmonthly= mysql_query($querymonthly);
$user_monthly_wins = mysql_num_rows($resultmonthly);


    if ( $user_monthly_wins >= $admin_monthly_win_limits ) {

echo "monthly";

    exit;
}


 






  

 $auctionends = $query435['ends'];
  $item_extend_activated = $query435['ae_activation'];
  $item_extend_increment = $query435['ae_increment'];
  $bid_credits_reqd1 = $query435['bid_credits_reqd'];
  $auction_type2 = $query435['auction_type2'];
             
             
             
                    if ( $lockout == 1 ) {
       
    $___END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) - 6, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
       
       if (($___END - $TIME) <= 180) {     
       
       
          $query = "select * from PHPAUCTIONXL_bids2
         WHERE bidder=$id2 AND auction=$auction_id";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);

if ( $num_auction == 0 ) {
       
           
echo "lockout";

    exit;
    
    }
    
    }
} 
  
 
            
      if ( $auction_type2 == "beginner" ) {
           if ( $beginner_wins >= $admin_beginner_auction_limit ){
echo "beginner";
    exit;
    }
}
  
           if ( $auction_type2 == "elite" ) {
           if ( $beginner_wins <= $admin_elite_auction_limit ){
echo "elite";
    exit;
    }
}

           if ( $seat_qty > 0 ) {
  
$queryseats = "select * from PHPAUCTIONXL_auction_seats
         WHERE auctionid=$auction_id AND userid=$id2";
$resultseats = mysql_query($queryseats);
$num_auctionseats = mysql_num_rows($resultseats);   

if ( $num_auctionseats == 0 ) {

     $queryseats2 = "select * from PHPAUCTIONXL_auction_seats
         WHERE auctionid=$auction_id";
$resultseats2 = mysql_query($queryseats2);
$num_auctionseats2 = mysql_num_rows($resultseats2); 
           
           if ( $num_auctionseats2 >= $seat_qty ){
echo "seatsfull";
    exit;
    }

      if ( $num_auctionseats2 < ($seat_qty + 1) ){

$query12 = "INSERT INTO PHPAUCTIONXL_auction_seats VALUES";

$query12 .= "(NULL";
$query12 .= ",";
$query12 .= $id2;
$query12 .= ",";
$query12 .= $auction_id;
$query12 .= ",";
$query12 .= 1;
$query12 .= ",";
$query12 .= 0;
$query12 .= ")";


mysql_query($query12);

$seatsupdate = $num_auctionseats2 +1;

$query34="UPDATE PHPAUCTIONXL_auctions2 SET seats_taken='$seatsupdate' WHERE id='$auction_id'";

mysql_query($query34);



}

}
}

        
  
     if ( $hard_reset_check == 0) {
  
  
  if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) - 6, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            
            if (($__END - $TIME) <= $EXTSETTINGS['timebefore']) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + $EXTSETTINGS['extend'] , substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

 
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) - 6, substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            
            if (($__END - $TIME) <= $item_extend_activated ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + $item_extend_increment , substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

 
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

              }
              
              
              
              if ( $hard_reset_check == 1) {
              
              
                        if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            $TIME_EXTEND = $EXTSETTINGS['timebefore'];
                     
                         $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $EXTSETTINGS['extend'] - $timeremaining22;
              
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

  
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
                $TIME_EXTEND = $item_extend_activated;
                          $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $item_extend_increment - $timeremaining22;
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

  
                
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

              
              
              
              
              
                                  }
                                  
                                  
                                  
                                  
                                  
$query99 = "select current_high_bidder,current_bid,increment,closed from PHPAUCTIONXL_auctions
         WHERE id=$auction_id";
$result = mysql_query($query99);
$num_auction = mysql_num_rows($result);

 $i = 0;
while($i < $num_auction) {

  $high_bidder 	= mysql_result($result,$i,"current_high_bidder");
$high_bid 	= mysql_result($result,$i,"current_bid");
   $increment 	= mysql_result($result,$i,"increment");
//   $closed = mysql_result($result,$i,"closed"); 
   
   
$i++;
}

          if ( 1 != 2 ) {

   

                     if ( $increment > 0 ) {          
$high_bid = $high_bid + $increment;
                             }
                             
       if ( $increment < 0 ) {
       if( $high_bid > .01 ) {          
$high_bid = $high_bid + $increment;
                             } }                           

if ( $increment < 0 ) {
       if( $high_bid <= .01 ) {          
$high_bid = .01;
                             } } 

if ($closed == 0 ) {              
        if ( $bids_remaining >= $bid_credits_reqd1 ) {           

                                  $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id";
                mysql_query($query69);
                      
                  $query692 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id";
                mysql_query($query692);

                         
$query1 = "INSERT INTO PHPAUCTIONXL_bids VALUES";

$query1 .= "(NULL";
$query1 .= ",";
$query1 .= $auction_id;
$query1 .= ",";
$query1 .= $id2;
$query1 .= ",";
$query1 .= $high_bid;
$query1 .= ",";
$query1 .= $NOW;
$query1 .= ",";
$query1 .= "1";
$query1 .= ",";
$query1 .= "'";
$query1 .= $username;
$query1 .= "'";
$query1 .= ",";
$query1 .= "'unique'";
$query1 .= ")";
            
            
            
mysql_query($query1);

            $query12 = "INSERT INTO PHPAUCTIONXL_bids2 VALUES";

$query12 .= "(NULL";
$query12 .= ",";
$query12 .= $auction_id;
$query12 .= ",";
$query12 .= $id2;
$query12 .= ",";
$query12 .= $high_bid;
$query12 .= ",";
$query12 .= $NOW;
$query12 .= ",";
$query12 .= "1";
$query12 .= ",";
$query12 .= "'";
$query12 .= $username;
$query12 .= "'";
$query12 .= ",";
$query12 .= "'unique'";
$query12 .= ")";
            
            
            
mysql_query($query12);


             
                              
                      
            
              

$query33="UPDATE PHPAUCTIONXL_auctions SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$auction_id'";

mysql_query($query33);


$query33a="UPDATE PHPAUCTIONXL_auctions2 SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$auction_id'";

mysql_query($query33a);



$bids_remaining2 = $bids_remaining - $bid_credits_reqd1;
 
 $query34="UPDATE PHPAUCTIONXL_users SET bids_remaining='$bids_remaining2' WHERE id='$id2'";

mysql_query($query34);

    $query99a = "select * from PHPAUCTIONXL_bids WHERE auction='$auction_id' ORDER BY id";
$result = mysql_query($query99a);
$num_auction = mysql_num_rows($result);

if ( $num_auction > 15 ) {

   $bidwhen1 	= mysql_result($result,2,"id");

   $removeold="DELETE from PHPAUCTIONXL_bids where id<'$bidwhen1' AND auction='$auction_id'";
mysql_query($removeold);

}



$echo22 = "yes|";
$echo22 .= $bid_credits_reqd1;

echo $echo22;
 }

}

}

}  
   
   }   
   
   }
      
   
   
   
   
   
//location.reload(true);

   
       
//include "get_time2cronbid.php";           
        
?>
